﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
using DevComponents.DotNetBar;


namespace QLST
{
    public partial class frmQuyen : Form

    {
        QuyenBUS cls = new QuyenBUS();
        QuyenDTO p = new QuyenDTO();
        public frmQuyen()
        {
            InitializeComponent();
        }

        private void frmQuyen_Load(object sender, EventArgs e)
        {
            loadQuyen();
        }
        public void loadQuyen()
        {
            cls.LoadQuyen();
        }

        private void DGVQuyen_SelectionChanged(object sender, EventArgs e)
        {
            txtMaQuyen .Text =gvQuyen .CurrentRow .Cells["colMaQuyen"].Value .ToString ();
            txtTenQuyen .Text =gvQuyen .CurrentRow .Cells ["colTenQuyen"].Value .ToString ();
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
           
            p.MaQuyen = txtMaQuyen.Text;
            p.TenQuyen = txtTenQuyen.Text;

            cls.Is_Quyen(p);
            ClearGV();
            frmQuyen_Load(sender, e);
            gvQuyen.Enabled = true;
            MessageBoxEx.Show("Cập nhật thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

            
        }
        // them
        private void btnQThem_Click(object sender, EventArgs e)
        {
            LockButton(false);
            LockTextBox(true);
            ClearTextBox();
            gvQuyen.Enabled = false;
            txtTenQuyen.Focus();
        }

        //xoa
        private void btnQXoa_Click(object sender, EventArgs e)
        {
            p.MaQuyen  = txtMaQuyen .Text ;

            cls.Del_Quyen(p);
            frmQuyen_Load(sender, e);
        }
        //
        private void btnQHuy_Click(object sender, EventArgs e)
        {
            ClearGV();
            frmQuyen_Load(sender, e);
            LockButton(true);
            LockTextBox(false);
            gvQuyen.Enabled = true;
        }


        private void ClearGV()
        {
            gvQuyen.ClearSelection();
        }

        private void ClearTextBox()
        {
            txtMaQuyen.Text = "";
            txtTenQuyen.Text = "";
        }

        private void LockButton(Boolean f)
        {
            btnQThem.Enabled = f;
            btnQXoa.Enabled = f;
            btnQLuu.Enabled = !f;
            btnQHuy.Enabled = !f;
        }

        private void LockTextBox(Boolean f)
        {
            txtMaQuyen.Enabled = f;
            txtTenQuyen.Enabled = f;
            if (f == false)
            {
                txtTenQuyen.BackColor = Color.LemonChiffon;
                txtMaQuyen.BackColor = Color.LemonChiffon;
            }
            else if (f == true)
            {
                txtTenQuyen.BackColor = Color.White;
                txtMaQuyen.BackColor = Color.White;
            }
        }

       
       

        

    }
}
